<%-- 
    Document   : home
    Created on : 09.12.2011, 11:43:02
    Author     : Дима
--%>

<%@page import="encaps.utils.ActionExecutor"%>
<%@page import="javax.naming.*"%>
<%@page import="encaps.entities.UserLocalHome"%>
<%@page import="encaps.action.Action"%>
<%@page import="java.util.*"%>
<%@page import="encaps.utils.RequestParser"%>
<%@page import="encaps.entities.Role"%>
<%@page import="encaps.utils.StringUtil"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <%!
        public static final String USER_ROLE = "role";
        RequestParser requestParser = new RequestParser();
        
        public void init() throws ServletException {

        }
        %>

        <%
        String roleName = (String) session.getAttribute(USER_ROLE);
        if(StringUtil.isEmpty(roleName)) {
            roleName = Role.GUEST;
            session.setAttribute(USER_ROLE, roleName);
        }
        
        Action action = requestParser.parseRequest(request.getParameter("action"), request.getParameterMap());
        String result = ActionExecutor.executeAction(roleName, action);
        %>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>

    <body>
        <h1>Hello World!</h1>
        <%-- <%
        Map<String, String[]> map = request.getParameterMap();
        Collection<String> keys = map.keySet();
        for(String key: keys) {
        %>
        key: <%= key %>  val: <%= map.get(key)[0] %> <br>
        <% } %>
        <br><br>Default: <%= requestParser.getDefaultActionFactory() %><br> --%>
        <%= result %>
        <form action="home.jsp" method="post">
            <input type="text" name="login" size="10"/>
            <select name="select">
                <option value="val1">Some text 1</option>
                <option value="val2">Some text 2</option>
            </select>
            <input type="password" name="password" size="10">
            <button name="action" value="authorization">do action</button>
        </form>
        
    </body>
</html>
